<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>牧心农业</title>
    <link rel="stylesheet" type="text/css" href="/static/css/eui.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/style.css" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=GKTGV62UVGc1FZb4wUBdWG8w"></script>
</head>
<body>
    <div class="content relative">
        <div id="map" class="all_width all_height"></div>
        <div class="absolute block_70 bg_light circle back_icon text_center font_12 cursor"><i class="iconfont icon-back" style="font-size:30px"></i><div class="text_list">列表展示</div></div>
        <div class="absolute width_100 text_center white lineheight_3 navs" style="top:15%;left:7%;"></div>
        <div class="absolute all bg_dark flex farmer hide" style="padding:5% 7%;"></div>
        <div class="absolute all flex pig_info hide" style="padding:5% 4%;"></div>
    </div>
    <script type="text/template" charset="utf-8" id='county_template'>
        {{for (var i in it){ }}
            <div class="bg_gradient_dark margin_b_10 cursor" onclick="changecounty('{{=i}}')">{{=i}}</div>
        {{ } }}
    </script>
    <script type="text/template" charset="utf-8" id='town_template'>
        {{for (var i in it.data){ }}
            <div class="bg_gradient_dark margin_b_10 cursor" onclick="changetown('{{=it.name}}','{{=i}}')">{{=i}}</div>
        {{ } }}
    </script>
    <script type="text/template" charset="utf-8" id='village_template'>
        {{for (var i in it.data){ }}
            <div class="bg_gradient_dark margin_b_10 cursor" onclick="changevillage('{{=it.name0}}','{{=it.name}}','{{=i}}')">{{=i}}</div>
        {{ } }}
    </script>
    <script type="text/template" charset="utf-8" id='farmer_template'></script>
    <script type="text/template" charset="utf-8" id='pig_template'></script>
    <script type="text/template" charset="utf-8" id='record_template'></script>
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/doT.min.js"></script>
    <script src="/static/js/swiper.min.js"></script>
    <script src="/static/js/func.js"></script>
    <script>
        // 地图初始化
            var town = "";
            var evalcounty = doT.template($("#county_template").text());
            var evaltown = doT.template($("#town_template").text());
            var evalvillage = doT.template($("#village_template").text());
            var mp = new BMap.Map('map',{mapType: BMAP_HYBRID_MAP});
            setlocation(109.171,33.585,map_data1,11,0);
            $(".navs").html(evalcounty(map_data1))

            mp.addControl(new BMap.NavigationControl());
            mp.addControl(new BMap.ScaleControl());
            mp.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));
            mp.enableScrollWheelZoom(true);
        // 切换县
            function changecounty(n){
                town = n;
                setlocation(map_data1[n][0],map_data1[n][1],map_data2[n],12,1)
                $(".navs").html(evaltown({name:n,data:map_data2[n]}))
                $(".text_list").hide()
                $(".back_icon").addClass("town");
            }
        // 切换镇
            function changetown(n1,n2){
                setlocation(map_data2[n1][n2][0],map_data2[n1][n2][1],map_data3[n2],13,2)
                $(".navs").html(evalvillage({name0:n1,name:n2,data:map_data3[n2]}))
                $(".back_icon").removeClass("town").addClass("village");
            }
        // 切换村
            function changevillage(n0,n1,n2){
                setlocation(map_data3[n1][n2][0],map_data3[n1][n2][1],farmers[n2],13,3)
                // $(".navs").html(evalvillage(farmers[n2]))
            }
        // 切换地图中心点
            function setlocation(ln,lt,d,i,type){
                var p = new BMap.Point(ln,lt);
                mp.centerAndZoom(p, i);
                setdata(d,type);
            }
        // 载入标注点数据
            function setdata(d,type){
                mp.clearOverlays();
                for (var i in d) {
                    setPoint(d[i][0],d[i][1],i,type)
                }
            }
        // 设置标注点
            function setPoint(ln,lt,str,type){
                var p = new BMap.Point(ln,lt);
                var myIcon = new BMap.Icon("/static/images/location.png", new BMap.Size(28,28));
                var marker = new BMap.Marker(p,{icon:myIcon});
                var opts = {
                    width : 200,
                    height: 80,
                    title : str
                }
                if(type==3){
                    var infoWindow = new BMap.InfoWindow("<div class='info' onclick=\"getfarmer('"+str+"')\">查看农户详情</div>", opts);
                }else{
                    var infoWindow = new BMap.InfoWindow("地址：柞水县牧心农业有限公司", opts);
                }
                marker.addEventListener("click", function(){
                    mp.openInfoWindow(infoWindow,p); //开启信息窗口
                });
                mp.addOverlay(marker);
            }
        // 返回
            $(".back_icon").click(function(){
                if($(this).hasClass("village")){
                    setlocation(map_data1[town][0],map_data1[town][1],map_data2[town],12)
                    $(".navs").html(evaltown({name:town,data:map_data2[town]}))
                    $(".back_icon").removeClass("village").addClass("town")
                }else if($(this).hasClass("town")){
                    setlocation(109.171,33.585,map_data1,11);
                    $(".navs").html(evalcounty(map_data1))
                    $(".back_icon").removeClass("town")
                    $(".text_list").show()
                }else{
                    location.href="<{url route='site/farmer-list'}>";
                }
            })
        // 打开农户详情浮层
            function getfarmer(n){
                mp.clearOverlays();
                $(".BMap_mask").click()
                $(".navs").hide();
                getfarmerinfo(n)
            }
        // 关闭农户详情浮层
            function closefarmer(){
                $(".navs").show();
                $(".farmer").hide();
            }
    </script>
</body>
</html>
